﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;

namespace SeCompUFSCarWeb.Models
{
    public static class UsuarioAspNet
    {
        static public string Email(string id)
        {
            string retorno = "";
            //Configurando Conexão
            string strconn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            MySqlConnection conn = new MySqlConnection(strconn);


            //Query
            string query = "SELECT email FROM secomp.aspnetusers where id= @id";
            MySqlCommand cmd = new MySqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@id", id);


            try
            {
                conn.Open();
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    retorno = reader.GetString("email");
                }
            }
            catch (Exception)
            {
                conn.Close();
                return retorno;

            }
            finally
            {
                conn.Close();
            }

            return retorno;
        }

        static public string Id(string email)
        {
            string retorno = "";
            //Configurando Conexão
            string strconn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            MySqlConnection conn = new MySqlConnection(strconn);


            //Query
            string query = "SELECT id FROM secomp.aspnetusers where email= @email";
            MySqlCommand cmd = new MySqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@email", email);


            try
            {
                conn.Open();
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    retorno = reader.GetString("id");
                }
            }
            catch (Exception)
            {
                conn.Close();
                return retorno;
            }
            finally
            {
                conn.Close();
            }

            return retorno;
        }
    }
}